package com.ccx.demo.business.common.vo;

import com.alibaba.fastjson.annotation.JSONField;
import com.ccx.demo.config.init.AppConfig.Path;
import com.ccx.demo.config.init.AppConfig.URL;
import com.utils.util.FPath;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

/**
 * 用户头像文件对象
 *
 * @author 谢长春 on 2017/10/17.
 */
@ToString(callSuper = true)
@NoArgsConstructor
@ApiModel(description = "用户头像文件对象")
public class UserFileInfo extends FileInfo {

    private static final long serialVersionUID = -6779893372268172821L;

    public UserFileInfo(final FPath.FileName fileName) {
        super(fileName);
    }

    public static UserFileInfo valueOf(final FPath.FileName fileName) {
        return new UserFileInfo(fileName);
    }

    @JSONField(serialize = false, deserialize = false)
    @ApiModelProperty(hidden = true)
    private final String className = UserFileInfo.class.getSimpleName();

    @ApiModelProperty(hidden = true)
    @JSONField(serialize = false, deserialize = false)
    public String getPath() {
        return StringUtils.isEmpty(uname) ? null : Path.USER.get(uname);
    }

    public String getUrl() {
        return StringUtils.isEmpty(uname) ? null : URL.USER.append(uname);
    }

    @SneakyThrows
    public UserFileInfo cloneObject() {
        return (UserFileInfo) super.clone();
    }
}
